package com.citywithincity.crypt;

import java.security.Key;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;


public class AesDataCrypt implements IDataCrypt {
	
	private static final String AESTYPE = "AES/ECB/PKCS5Padding";
	
	@Override
	public byte[] encript(byte[] data, byte[] key) throws Exception {
		Key keySpec =  new SecretKeySpec(key, "AES");
		Cipher cipher = Cipher.getInstance(AESTYPE);
		cipher.init(Cipher.ENCRYPT_MODE, keySpec);
		return cipher.doFinal(data);
	}

	@Override
	public byte[] decript(byte[] data, byte[] key) throws Exception  {
		Key cKey = new SecretKeySpec(key, "AES");
		Cipher cipher = Cipher.getInstance(AESTYPE);
		cipher.init(Cipher.DECRYPT_MODE, cKey);
		return cipher.doFinal(data);
	}

}
